#include "painter.h"
#include<QMouseEvent>
Painter::Painter(QWidget *parent)
    : QWidget{parent}
{
    rgb = new RGB;
    paint_r=1;
}

void Painter::SetR(int range){
    paint_r=range;

}

void Painter::SetRGB(int r,int g,int b)
{
    rgb->r=r;
    rgb->b=b;
    rgb->g=g;
}

void Painter::MousePress(QMouseEvent *event){
    std::vector<QPoint> line;
    line.push_back(event->pos());
    lines.push_back(line);
}

void Painter::MouseMove(QMouseEvent *event){
    auto& line=lines[lines.size()-1];
    line.push_back(event->pos());
//    Painter::Changed();
}

void Painter::MouseRelease(QMouseEvent *event){
    auto& line = lines[lines.size()-1];
    line.push_back(event->pos());
}

void Painter::PaintLine(Image* img){
//    rgb->b=rgb->g=rgb->r=0;
    for(const auto &line:lines){
        for(int i=0;i<line.size()-1;i++){

            img->DrawLine(line.at(i).x(),img->Height()-line.at(i).y()-50,line.at(i+1).x(),img->Height()-line.at(i+1).y()-50,paint_r,rgb);
        }
    }
}

void Painter::Clear(){
    lines.clear();

}
